package com.lcc.controller;

import com.lcc.util.sendEmailToUserUtil;
import jakarta.mail.internet.MimeMessage;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class QQController {
    @Autowired
    private JavaMailSenderImpl mailSender;

    /**
     * 简单信息发送
     * @return
     * @throws Exception
     */
    @RequestMapping("/test")
    public @ResponseBody String sendEmail() throws Exception {
        SimpleMailMessage mailMessage = sendEmailToUserUtil.sendToUser();
        //发送邮件
        mailSender.send(mailMessage);
        return "发送邮件成功";
    }


    @RequestMapping("/test2")
    public @ResponseBody String sendEmail2() throws Exception {
        //创建邮件对象
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
        //调用方法
        sendEmailToUserUtil.sendToUser2(helper);
        //发送邮件
        mailSender.send(mimeMessage);
        return "发送邮件成功";
    }

}
